package com.zhao.dota.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhao.dota.contant.CacheConstant;
import com.zhao.dota.mapper.LeagueUserGroupMapper;
import com.zhao.dota.model.LeagueUserGroup;
import com.zhao.dota.service.LeagueUserGroupService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;

import javax.swing.text.WrappedPlainView;

@Service
public class LeagueUserGroupServiceImpl extends ServiceImpl<LeagueUserGroupMapper, LeagueUserGroup> implements LeagueUserGroupService {

    @Override
    public LeagueUserGroup save(Integer leagueId, Integer userId, Integer groupId) {
        LambdaQueryWrapper<LeagueUserGroup> query = Wrappers.lambdaQuery(LeagueUserGroup.class)
                .eq(LeagueUserGroup::getLeagueId, leagueId)
                .eq(LeagueUserGroup::getUserId, userId);
        LeagueUserGroup leagueUserGroup = getOne(query);
        if (leagueUserGroup == null) {
            leagueUserGroup = new LeagueUserGroup();
            leagueUserGroup.setLeagueId(leagueId);
            leagueUserGroup.setUserId(userId);
            leagueUserGroup.setGroupId(groupId);
            save(leagueUserGroup);
        } else {
            leagueUserGroup.setGroupId(groupId);
            updateById(leagueUserGroup);
        }
        return leagueUserGroup;
    }

}
